package com.tanhua.server.controller;

import com.tanhua.domain.db.UserInfo;
import com.tanhua.domain.mongo.UserLike;
import com.tanhua.dubbo.api.mongo.UserLikeApi;
import com.tanhua.server.service.UserService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

//value  object
import java.io.IOException;

@RestController
@RequestMapping("/users")
@Slf4j
public class UserInfoController {

    @Autowired
    private UserService userService;



    /**
     *接口名称：用户资料 - 读取
     *接口路径：GET/users
     */
   @GetMapping
    public ResponseEntity findUserInfoById(Long userID,Long huanxinID) throws IOException {
       log.info("========UserInfoController查询用户的信息========UserId==="+userID+"======huanxinID========?"+huanxinID);
        return userService.findUserInfoById(userID,huanxinID);
    }


    /**
     *接口名称：用户资料 - 保存
     *  接口路径：PUT/users
     */
    @PutMapping
    public ResponseEntity updateUserInfo(@RequestHeader("Authorization") String token,@RequestBody UserInfo userInfo) throws IOException {
        return userService.updateUserInfo(userInfo,token);
    }


    /**
     *接口名称：互相喜欢，喜欢，粉丝 - 统计
     *接口路径：GET/users/counts
     */
    @GetMapping("/counts")
    public ResponseEntity queryCounts() {
        return userService.queryCounts();
    }


    /**
     *接口名称：互相喜欢、喜欢、粉丝、谁看过我 - 翻页列表\
     * 接口路径：GET /users/friends/:type
     */
    @GetMapping("/friends/{type}")
    public ResponseEntity queryUserLikeList(@RequestParam(defaultValue = "1") Integer page,
                                      @RequestParam(defaultValue = "10") Integer pagesize,String nickname,
                                      @PathVariable("type") Integer type) {
        return userService.queryUserLikeList(page,pagesize,nickname,type);
    }


    /**
     *接口名称：粉丝 - 喜欢
     *接口路径：POST/users/fans/:uid
     *
     */
    @PostMapping("/fans/{uid}")
    public ResponseEntity fansLike(@PathVariable("uid") Long fansId) {
        return userService.fansLike(fansId);
    }


    /**
     *接口名称：是否喜欢（新增接口）
     *接口路径：GET/users/:uid/alreadyLove
     *
     */
    @GetMapping("/{uid}/alreadyLove")
    public ResponseEntity alreadyLove(@PathVariable("uid") Long loveId){
        return userService.addLike(loveId);
    }

}
